import 'dart:ui';

import 'package:extended_tabs/extended_tabs.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:live_music/components/ui/theme.dart';
import 'package:live_music/pages/home/index/page_view/discover_index.dart';
import 'package:live_music/pages/home/index/page_view/follow_index.dart';
import 'package:live_music/pages/search/index.dart';
import 'package:live_music/pages/search/widget/moment_search.dart';
import 'package:live_music/pages/search/widget/user_search.dart';

class SearchResultIndex extends StatefulWidget {
  SearchResultIndex({Key key, this.keyword}) : super(key: key);
  String keyword;
  @override
  _SearchResultIndexState createState() => _SearchResultIndexState();
}

class _SearchResultIndexState extends State<SearchResultIndex>
    with AutomaticKeepAliveClientMixin, SingleTickerProviderStateMixin {
  TabController _tabController;
  List<Widget> _tabsContent;
  final List<Widget> _tabs = [Text('全部'), Text('用户')];
  @override
  void initState() {
    super.initState();
    _tabsContent = [
      MomentSearch(keyword: widget.keyword),
      UserSearchPage(keyword: widget.keyword)
    ];
    _tabController = TabController(
      initialIndex: 0,
      length: _tabs.length,
      vsync: this,
    );
  }

  @override
  Widget build(BuildContext context) {
    super.build(context);
    return Container(
        height: MediaQuery.of(context).size.height - 40,
        child: Column(
          children: [
            _getTopBarLayout(),
            Container(
                height: MediaQuery.of(context).size.height - 129,
                child: ExtendedTabBarView(
                  controller: _tabController,
                  children: _tabsContent,
                )),
          ],
        ));
  }

  _getTopBarLayout() {
    return Container(
      height: 40,
      color: Colors.white,
      alignment: Alignment.center,
      padding: EdgeInsets.only(bottom: 10),
      child: Container(
          width: 0.35 * MediaQuery.of(context).size.width,
          child: ExtendedTabBar(
            indicatorSize: TabBarIndicatorSize.label,
            controller: _tabController,
            indicatorColor: Colors.red,
            indicatorWeight: 3,
            unselectedLabelStyle: TextStyle(
                color: Colors.grey[600], // 下划线颜色
                fontSize: 15,
                fontWeight: FontWeight.w600),
            labelStyle: TextStyle(
                color: Colors.white,
                fontSize: 15,
                fontWeight: FontWeight.w700), //标签文字大小颜色
            tabs: _tabs,
          )),
    );
  }

  @override
  bool get wantKeepAlive => true;
}
